package com.ptppay.cf.coin.service.btc;

import com.ptppay.cf.coin.service.btc.domain.SPKey;
import com.ptppay.cf.coin.service.btc.request.CreateEmptyWalletRequest;
import com.ptppay.cf.coin.service.btc.request.CreateKeyChainSeedRequest;
import com.ptppay.cf.coin.service.btc.request.CreateSPKeyRequest;
import com.ptppay.cf.coin.service.btc.request.CreateWalletSPKeyRequest;
import com.ptppay.cf.coin.service.btc.request.TransferCoinRequest;
import com.ptppay.cf.coin.service.btc.request.WalletBalanceRequest;
import com.ptppay.cf.coin.service.btc.response.CreateEmptyWalletResponse;
import com.ptppay.cf.coin.service.btc.response.CreateKeyChainSeedResponse;
import com.ptppay.cf.coin.service.btc.response.CreateSPKeyResponse;
import com.ptppay.cf.coin.service.btc.response.CreateWalletSPKeyResponse;
import com.ptppay.cf.coin.service.btc.response.TransferCoinResponse;
import com.ptppay.cf.coin.service.btc.response.WalletBalanceResponse;

import cn.finder.httpcommons.IClient;
import cn.finder.wae.httpcommons.ApiConfig.ServiceInterfaceConfig;
import cn.finder.wae.httpcommons.HttpPostClient;

public class BtcApiService {

	/***
	 * 获取上传电话数据的任务
	 * @param req
	 * @return
	 */
	public double getWalletBalance(String url,String wallet_id){
		
		IClient client = new HttpPostClient(ServiceInterfaceConfig.getServiceInterfaceUrlExt(url,"fields"), ServiceInterfaceConfig.AppKey, ServiceInterfaceConfig.AppSecret);
		WalletBalanceRequest req=new WalletBalanceRequest();
		req.setWallet_id(wallet_id);
		
		WalletBalanceResponse resp= client.execute(req);

		return resp.getBalance();
	}
	
	
	/***
	 * 获取上传电话数据的任务
	 * @param req
	 * @return
	 */
	public String createEmptyWallet(String url){
		
		IClient client = new HttpPostClient(ServiceInterfaceConfig.getServiceInterfaceUrlExt(url,"fields"), ServiceInterfaceConfig.AppKey, ServiceInterfaceConfig.AppSecret);
		CreateEmptyWalletRequest req=new CreateEmptyWalletRequest();
		
		CreateEmptyWalletResponse resp= client.execute(req);

		return resp.getSeeds();
	}
	
	
	/***
	 * 获取上传电话数据的任务
	 * @param req
	 * @return
	 */
	public String createKeyChainSeed(String url,String wallet_id){
		
		IClient client = new HttpPostClient(ServiceInterfaceConfig.getServiceInterfaceUrlExt(url,"fields"), ServiceInterfaceConfig.AppKey, ServiceInterfaceConfig.AppSecret);
		CreateKeyChainSeedRequest req=new CreateKeyChainSeedRequest();
		req.setWallet_id(wallet_id);
		CreateKeyChainSeedResponse resp= client.execute(req);
		
		return resp.getSeeds();
	}
	
	/***
	 * 获取上传电话数据的任务
	 * @param req
	 * @return
	 */
	public SPKey createSPKey(String url){
		
		IClient client = new HttpPostClient(ServiceInterfaceConfig.getServiceInterfaceUrlExt(url,"fields"), ServiceInterfaceConfig.AppKey, ServiceInterfaceConfig.AppSecret);
		CreateSPKeyRequest req=new CreateSPKeyRequest();
		CreateSPKeyResponse resp= client.execute(req);
		
		if(resp.isSuccess())
			return resp.getEntities().get(0);
		else
			return null;
	}
	
	
	/***
	 * 获取上传电话数据的任务
	 * @param req
	 * @return
	 */
	public SPKey createSPKey(String url,String wallet_id){
		
		IClient client = new HttpPostClient(ServiceInterfaceConfig.getServiceInterfaceUrlExt(url,"fields"), ServiceInterfaceConfig.AppKey, ServiceInterfaceConfig.AppSecret);
		CreateWalletSPKeyRequest req=new CreateWalletSPKeyRequest();
		req.setWallet_id(wallet_id);
		CreateWalletSPKeyResponse resp= client.execute(req);
		if(resp.isSuccess())
			return resp.getEntities().get(0);
		else
			return null;
	}
	
	
	/***
	 * 获取上传电话数据的任务
	 * @param req
	 * @return
	 */
	public String transferCoin(String url,String wallet_id,String wallet,double coin_amt){
		
		IClient client = new HttpPostClient(ServiceInterfaceConfig.getServiceInterfaceUrlExt(url,"fields"), ServiceInterfaceConfig.AppKey, ServiceInterfaceConfig.AppSecret);
		TransferCoinRequest req=new TransferCoinRequest();
		req.setWallet_id(wallet_id);
		req.setWallet(wallet);
		req.setCoin_amt(coin_amt);
		TransferCoinResponse resp= client.execute(req);
		
		return resp.getTxHash();
	}
	
	
	
	
	
}
